﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MyMainSite.Repositories;

namespace MyMainSite.Factories
{
    public static class RepositoryFactory<T> where T: class, IRepository
    {
        #region Properties

        public static T Repository
        {
            get { return RepositoryFactory<T>._repository; }
            set { RepositoryFactory<T>._repository = value; }
        }
        private static T _repository = null;

        #endregion

        #region Public Static Methods

        public static void SetRepository(T repository)
        {
            RepositoryFactory<T>._repository = repository;
        }

        public static T GetRepository()
        {
            T repo = null;

            if (RepositoryFactory<T>.Repository == null)
            {
                repo = (T)Activator.CreateInstance<T>();
            }
            else
            {
                repo = RepositoryFactory<T>.Repository;
            }

            return repo;
        }

        #endregion
    }
}